#!usr/bin/env python
#coding=utf-8

import rss
from bs4 import BeautifulSoup as bs
import requests

__all__=['CnbetaParser',
        'KrParser',
        "FTParser",
        'YeeyanParser',
        "BoleParser"
        ]

class CnbetaParser(rss.Parser):
    url='http://rss.cnbeta.com/rss'
    
class KrParser(rss.Parser):
    url="http://www.36kr.com/feed"

class FTParser(rss.Parser):
    url="http://www.ftchinese.com/rss/feed"

class BoleParser(rss.Parser):
    url="http://python.jobbole.com/feed/"
'''
class YeeyanParser(rss.SParser):
    url="http://feed.yeeyan.org/select"
 
    def __init__(self):
        xml=requests.get(self.url).text
        self.root=bs(xml,"xml").feed
    
    def getfields(self):
        self.fields=self.root.find_all("entry")      #tag=="entry"
        
    def run(self):
        self.getfields()
        for item in self.fields:
            title=item.title.get_text()
            #link=item.link["href"]
            link=item.link.get("href")      #href is a attribution under the tag <entry> <link href="XXX">
            date=item.published.get_text()      #<entry>   <published>
            description=item.content.text     #<entry>   <content>

            #title=''.join(item.xpath("title/text()"))
            #link=''.join(item.xpath("link/@href"))
            #date=''.join(item.xpath("./pubDate/text()"))
            #description=''.join(item.xpath('content/text()'))

            newsitem=rss.Item(title,link,date,description)
            yield newsitem
'''
class YeeyanParser(rss.BSParser):
    url="http://feed.yeeyan.org/select"    
    def __init__(self):
        xml=requests.get(self.url).text
        self.soup=bs(xml,"xml").feed
        
    def getfields(self,tag="entry"):
        return super(YeeyanParser,self).getfields(tag)
        
    def getdate(self,obj,tag="published"):
        return super(YeeyanParser,self).getdate(obj,tag)
        
    def getdescription(self,obj,tag="content"):
        return super(YeeyanParser,self).getdescription(obj,tag)
        
if __name__=="__main__":
    node=CnbetaParser()
    for item in node.run():
        print item
    
